﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;

namespace MyLiveMesh.Web
{
    [ServiceContract(Namespace = "")]
    [SilverlightFaultBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1
    {
        //MeshDataObjectsDataContext db = new MeshDataObjectsDataContext("C:\\Users\\" + Environment.UserName + "\\base.mdf");

        [OperationContract]
        public bool connect(string name, string password)
        {
            // Add your operation implementation here
            return true;
        }

        private DirectoryTree tree = new DirectoryTree()
{
    Name = "mon dossier",
    Id = 1,
    Files = new List<FileDesc>() { new FileDesc() { Name = "file1.txt", Id = 1, Uri = "file1.txt" } },
    Children = new List<DirectoryTree>()
            {
                new DirectoryTree(){
                    Name = "mon sous dossier",
                    Id = 2,
                    Files = new List<FileDesc>() { new FileDesc() { Name = "file3.txt", Id = 3, Uri = "file3.txt" }, new FileDesc() { Name = "file2.txt", Id = 2, Uri = "file2.txt" } }
                },
                new DirectoryTree(){
                    Name = "mon sous dossier 2",
                    Id = 3,
                    Files = new List<FileDesc>() { new FileDesc() { Name = "file4.txt", Id = 4, Uri = "file4.txt" } },
                    Children = new List<DirectoryTree>()
            {
                new DirectoryTree(){
                    Name = "mon sous dossier",
                    Id = 2,
                    Files = new List<FileDesc>() { new FileDesc() { Name = "file3.txt", Id = 3, Uri = "file3.txt" }, new FileDesc() { Name = "file2.txt", Id = 2, Uri = "file2.txt" } }
                },
                new DirectoryTree(){
                    Name = "mon sous dossier 2",
                    Id = 3,
                    Files = new List<FileDesc>() { new FileDesc() { Name = "file4.txt", Id = 4, Uri = "file4.txt" } } 
                }
            }
                }
            }
};

        [OperationContract]
        public DirectoryTree getDirectoryTree()
        {
            return tree;
        }

        private List<string> f = new List<string>() { "toto", "tata" };

        [OperationContract]
        public bool addFriend(string name) { f.Add(name); return true; }

        [OperationContract]
        public void removeFriend(string email) { f.Remove(email); }

        [OperationContract]
        public List<string> getFriends() { return f; }

        // Add more operations here and mark them with [OperationContract]
    }

    public class FileDesc
    {
        string name;
        string uri;
        int id;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public string Uri
        {
            get { return uri; }
            set { uri = value; }
        }

        public int Id
        {
            get { return id; }
            set { id = value; }
        }
    }

    public class DirectoryTree
    {
        string name;
        int id;
        List<DirectoryTree> children;
        List<FileDesc> files;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        public List<DirectoryTree> Children
        {
            get { return children; }
            set { children = value; }
        }

        public List<FileDesc> Files
        {
            get { return files; }
            set { files = value; }
        }
    }
}
